package com.jiangtai.smartbox.util

import android.app.ActivityManager
import android.content.Context
import com.jiangtai.smartbox.application.App

/**
 * Created by hecuncun on 2020/12/30
 */
object ServiceUtil{
    /**
     * 判断服务是否运行
     */
    fun  isServiceRunning(className: String): Boolean {
        val activityManager = App.context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager?
        val info = activityManager?.getRunningServices(Integer.MAX_VALUE)
        if (info == null || info.size == 0) return false
        for (aInfo in info) {
            if (className == aInfo.service.className) return true
        }
        return false
    }
}